home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
optivc32
/
mdstd.h
< prev
next >
Wrap
C/C++ Source or Header
|
1999-03-06
|
59KB
|
1,086 lines
/* MDstd.h
matrix management functions:
manipulations on matrices of data type "double"
(double-precision real numbers)
Copyright (c) 1996-1999 by Martin Sander
All Rights Reserved.
*/
#if !defined( __MDSTD_H )
#define __MDSTD_H
#if !defined( __MATLIB_H )
#include <MatLib.h>
#endif
#if !defined( __VDSTD_H )
#include <VDstd.h>
#endif
#if !defined( __VDMATH_H )
#include <VDmath.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/************* Dynamic Generation of Matrices ************************/
dMatrix __vf MD_matrix( unsigned ht, unsigned len );
dMatrix __vf MD_matrix0( unsigned ht, unsigned len );
/* notice that, in the memory model HUGE,
neither len nor ht may exceed 4095 */
/***************************************************************************
* The following definitions ensure compatibility between dynamically *
* and statically allocated matrices. The definitions are somewhat *
* cumbersome, but the result for you is that you need not care about *
* the differences between the two types. *
* (Internally, the address of the first element of any matrix is needed; *
* the expression "MA[0]" is evaluated in a different way for both types, *
* but yields in either case the correct address to be passed to the *
* function you wish to call.) *
* Only in the rare case that you need to pass the address of one of *
* these functions as an argument to another function, you have to use *
* the actual run-time functions defined further below. Be careful with *
* this: future development of compilers may allow us to avoid this un- *
* handy scheme of macros. So future versions of MatrixLib may no longer *
* use these run-time names. *
***************************************************************************/
/*** Addressing single elements of dynamically allocated matrices: ******
These two functions are for compatibility with Pascal
(where elements of dynamically allocated matrices are not directly
accessible), and for getting around the pointer arithmetics bug in
some versions of Borland C++. */
#define MD_Pelement( MA, ht, len, m, n ) MDPelement( MA[0], ht, len, m, n )
/* returns a pointer to MA[m][n]. */
#define MD_element( MA, ht, len, m, n ) *MDPelement( MA[0], ht, len, m, n )
/* dereferenced pointer */
/**************** Initialization ***************************************
To initialize all elements of a matrix with the same value,
or to perform arithmetic operations on all elements simultaneously,
refer to the functions of VectorLib, declared in <VDstd.h>, <VDmath.h>.
In order to use the VectorLib functions, utilize the feature that
the whole matrix occupies one contiguous area in memory: pass the
address of the first row to the desired vector function, the size
of the "vector" being ht * len.
For example, initialize all elements of the matrix MA with 1.0
(this is *NOT* the identity matrix) by calling
VD_equ1( MA[0], ht * len );
*/
#define MD_equ0( MA, ht, len ) VD_equ0( MA[0], ((ui)ht)*len )
#define MD_equ1( MA, len ) MDequ1( MA[0], len )
/* this is the identity matrix */
#define MD_outerprod( MA, X, Y, ht, len ) MDouterprod( MA[0], X, Y, ht, len )
/* sizX=ht, sizY=len */
#define MD_Row_equC( MA, ht, len, iRow, C ) \
MDRow_equC( MA[0], ht, len, iRow, C )
#define MD_Col_equC( MA, ht, len, iCol, C ) \
MDCol_equC( MA[0], ht, len, iCol, C )
#define MD_Dia_equC( MA, len, C ) MDDia_equC( MA[0], len, C )
#define MD_Row_equV( MA, ht, len, iRow, X ) \
MDRow_equV( MA[0], ht, len, iRow, X )
#define MD_Col_equV( MA, ht, len, iCol, X ) \
MDCol_equV( MA[0], ht, len, iCol, X )
#define MD_Dia_equV( MA, len, X ) MDDia_equV( MA[0], len, X )
#define MD_equM( MB, MA, ht, len ) VD_equV( MB[0], MA[0], (ui)(ht)*(len) )
#define MD_UequL( MA, len ) MDUequL( MA[0], len )
#define MD_LequU( MA, len ) MDLequU( MA[0], len )
/* copy lower-diagonal elements into upper-diagonal
(or vice versa) by index-reflection, so as to
get a symmetric matrix */
/* data-type conversions: */
#define M_DtoF( MF, MD, ht, len ) V_DtoF( MF[0], MD[0], ((ui)ht)*len )
#define M_FtoD( MD, MF, ht, len ) V_FtoD( MD[0], MF[0], ((ui)ht)*len )
#define M_EtoD( MD, ME, ht, len ) V_EtoD( MD[0], ME[0], ((ui)ht)*len )
#define M_DtoE( ME, MD, ht, len ) V_DtoE( ME[0], MD[0], ((ui)ht)*len )
/* suitable windows for MF_spectrum: */
#define MD_Hanning( MA, ht, len ) MDHanning( MA[0], ht, len )
#define MD_Parzen( MA, ht, len ) MDParzen( MA[0], ht, len )
#define MD_Welch( MA, ht, len ) MDWelch( MA[0], ht, len )
/******** Extracting a submatrix and copying a submatrix back *********/
#define MD_submatrix( MSub, subHt, subLen, \
MSrce, srceHt, srceLen, \
firstRowInCol, sampInCol, firstColInRow, sampInRow ) \
MDsubmatrix( MSub[0], subHt, subLen, \
MSrce[0], srceHt, srceLen, \
firstRowInCol, sampInCol, firstColInRow, sampInRow )
#define MD_submatrix_equM( MDest, destHt, destLen, \
firstRowInCol, sampInCol, firstColInRow, sampInRow, \
MSrce, srceHt, srceLen ) \
MDsubmatrix_equM( MDest[0], destHt, destLen, \
firstRowInCol, sampInCol, firstColInRow, sampInRow, \
MSrce[0], srceHt, srceLen )
/***** Extracting a single row or a single column or the diagonal ******
* and storing it into a vector */
#define MD_Row_extract( Y, MA, ht, len, iRow ) \
MDRow_extract( Y, MA[0], ht, len, iRow )
#define MD_Col_extract( Y, MA, ht, len, iCol ) \
MDCol_extract( Y, MA[0], ht, len, iCol )
#define MD_Dia_extract( Y, MA, len ) MDDia_extract( Y, MA[0], len )
/***************** Basic arithmetic operations *********************
performed on one single row,
or one single column of any matrix,
or on the diagonal of a square matrix
Note: In contrast to the analogous VectorLib functions, the operations
are performed in-place, i.e. the input matrix itself is changed */
#define MD_Row_addC( MA, ht, len, iRow, C ) \
MDRow_addC( MA[0], ht, len, iRow, C )
#define MD_Col_addC( MA, ht, len, iCol, C ) \
MDCol_addC( MA[0], ht, len, iCol, C )
#define MD_Dia_addC( MA, len, C ) MDDia_addC( MA[0], len, C )
#define MD_Row_addV( MA, ht, len, iRow, X ) \
MDRow_addV( MA[0], ht, len, iRow, X )
#define MD_Col_addV( MA, ht, len, iCol, X ) \
MDCol_addV( MA[0], ht, len, iCol, X )
#define MD_Dia_addV( MA, len, X ) MDDia_addV( MA[0], len, X )
#define MD_Row_subC( MA, ht, len, iRow, C ) \
MDRow_addC( MA[0], ht, len, iRow, (-C) )
#define MD_Col_subC( MA, ht, len, iCol, C ) \
MDCol_addC( MA[0], ht, len, iCol, (-C) )
#define MD_Dia_subC( MA, len, C ) MDDia_addC( MA[0], len, (-C) )
#define MD_Row_subV( MA, ht, len, iRow, X ) \
MDRow_subV( MA[0], ht, len, iRow, X )
#define MD_Col_subV( MA, ht, len, iCol, X ) \
MDCol_subV( MA[0], ht, len, iCol, X )
#define MD_D